package com.tiantai.tea.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tiantai.common.annotation.Log;
import com.tiantai.common.core.controller.BaseController;
import com.tiantai.common.core.domain.AjaxResult;
import com.tiantai.common.enums.BusinessType;
import com.tiantai.tea.domain.TeaHomestay;
import com.tiantai.tea.service.ITeaHomestayService;
import com.tiantai.common.utils.poi.ExcelUtil;
import com.tiantai.common.core.page.TableDataInfo;

/**
 * 茶民宿管理Controller
 * 
 * @author handsomedog
 * @date 2024-09-28
 */
@RestController
@RequestMapping("/tea/homestay")
public class TeaHomestayController extends BaseController
{
    @Autowired
    private ITeaHomestayService teaHomestayService;

    /**
     * 查询茶民宿管理列表
     */
//    @PreAuthorize("@ss.hasPermi('tea:homestay:list')")
    @GetMapping("/list")
    public TableDataInfo list(TeaHomestay teaHomestay)
    {
        startPage();
        List<TeaHomestay> list = teaHomestayService.selectTeaHomestayList(teaHomestay);
        return getDataTable(list);
    }

    /**
     * 导出茶民宿管理列表
     */
    @PreAuthorize("@ss.hasPermi('tea:homestay:export')")
    @Log(title = "茶民宿管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TeaHomestay teaHomestay)
    {
        List<TeaHomestay> list = teaHomestayService.selectTeaHomestayList(teaHomestay);
        ExcelUtil<TeaHomestay> util = new ExcelUtil<TeaHomestay>(TeaHomestay.class);
        util.exportExcel(response, list, "茶民宿管理数据");
    }

    /**
     * 获取茶民宿管理详细信息
     */
//    @PreAuthorize("@ss.hasPermi('tea:homestay:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(teaHomestayService.selectTeaHomestayById(id));
    }

    /**
     * 新增茶民宿管理
     */
    @PreAuthorize("@ss.hasPermi('tea:homestay:add')")
    @Log(title = "茶民宿管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TeaHomestay teaHomestay)
    {
        return toAjax(teaHomestayService.insertTeaHomestay(teaHomestay));
    }

    /**
     * 修改茶民宿管理
     */
    @PreAuthorize("@ss.hasPermi('tea:homestay:edit')")
    @Log(title = "茶民宿管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TeaHomestay teaHomestay)
    {
        return toAjax(teaHomestayService.updateTeaHomestay(teaHomestay));
    }

    /**
     * 删除茶民宿管理
     */
    @PreAuthorize("@ss.hasPermi('tea:homestay:remove')")
    @Log(title = "茶民宿管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(teaHomestayService.deleteTeaHomestayByIds(ids));
    }
}
